/*
 * AlternationColorTableCellRenderer.java
 *
 * Created on 2007å¹´9æœˆ14æ—¥, ä¸Šå�ˆ10:32
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package packVistas;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author java
 */
public class ColumnColorTableCellRenderer extends DefaultTableCellRenderer{
    
    private Color colorOne = Color.white;
    private Color colorTwo = new Color(206,231,255);
    
    private Color textColor = Color.BLUE;
    private Color numberColor = Color.RED;
    private Color dateColor = Color.BLUE;
    
    /** Creates a new instance of AlternationColorTableCellRenderer */
    public ColumnColorTableCellRenderer(Color one, Color two) {
        if(one != null)
            colorOne = one;
        if(two != null)
            colorTwo = two;
    }
    
    public ColumnColorTableCellRenderer() {
    }
    
    public Component getTableCellRendererComponent(JTable table,
            Object value, boolean isSelected, boolean hasFocus,
            int row, int column) {
        
        if(value instanceof String)
        {
            String str = (String)value;
            this.setForeground(textColor);
            
        }else if(value instanceof Integer || value instanceof Double || value instanceof Long)
        {
            this.setForeground(numberColor);
            this.setHorizontalAlignment(SwingConstants.RIGHT);
        }
        if(row % 2 == 0){
            setBackground(colorOne);
        }
        else if(row % 2 == 1)
        {
            setBackground(colorTwo); 
        }
        return super.getTableCellRendererComponent(table, value,
                isSelected, hasFocus, row, column);
    }

    public Color getTextColor() {
        return textColor;
    }

    public void setTextColor(Color textColor) {
        this.textColor = textColor;
    }

    public Color getNumberColor() {
        return numberColor;
    }

    public void setNumberColor(Color numberColor) {
        this.numberColor = numberColor;
    }

    public Color getDateColor() {
        return dateColor;
    }

    public void setDateColor(Color dateColor) {
        this.dateColor = dateColor;
    }
}
